package com.cloud.myhystrix.controller;

import com.cloud.domain.TOrder;
import com.cloud.myhystrix.anno.MyHystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.security.PublicKey;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/7/2 9:02
 * @Desc
 * @Remarks
 */
@RestController
public class MyController {

    @Autowired
    RestTemplate restTemplate;

    @MyHystrixCommand(fallback = "fallback", timeout = 2000)
    @RequestMapping("/myhystrix/test")
    public TOrder test() {
        return restTemplate.getForObject("http://CLOUD-PRODUCER/domain/t-order/timeout?id=1", TOrder.class);
    }

    public TOrder fallback() {
        System.out.println("我的降级方法");
        return null;
    }
}
